<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="计算机网络实训之简单文件传输系统器, 十二惊惶的gitee">
    <meta name="description" content="只能说计算机网络实训那一周我是真的难受，不仅仅有我自己的实训任务还有别人的，自己这个任务一实际上是第一天就写完了的，大部分的时间是在做网络的一些内容，以及同组其他成员的可视化。

[TOC]
简单文件传输系统器简介本文件传输系统为一款实现内">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="referrer" content="no-referrer-when-downgrade">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>计算机网络实训之简单文件传输系统器 | 十二惊惶的gitee</title>
    <link rel="icon" type="image/png" href="/shier_jinghuang/favicon.png">
    


    <!-- bg-cover style     -->



<link rel="stylesheet" type="text/css" href="/shier_jinghuang/libs/awesome/css/all.min.css">
<link rel="stylesheet" type="text/css" href="/shier_jinghuang/libs/materialize/materialize.min.css">
<link rel="stylesheet" type="text/css" href="/shier_jinghuang/libs/aos/aos.css">
<link rel="stylesheet" type="text/css" href="/shier_jinghuang/libs/animate/animate.min.css">
<link rel="stylesheet" type="text/css" href="/shier_jinghuang/libs/lightGallery/css/lightgallery.min.css">
<link rel="stylesheet" type="text/css" href="/shier_jinghuang/css/matery.css">
<link rel="stylesheet" type="text/css" href="/shier_jinghuang/css/my.css">
<link rel="stylesheet" type="text/css" href="/shier_jinghuang/css/dark.css" media="none" onload="if(media!='all')media='all'">




    <link rel="stylesheet" href="/shier_jinghuang/libs/tocbot/tocbot.css">
    <link rel="stylesheet" href="/shier_jinghuang/css/post.css">




    



    <script src="/shier_jinghuang/libs/jquery/jquery-3.6.0.min.js"></script>

<meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/shier_jinghuang/atom.xml" title="十二惊惶的gitee" type="application/atom+xml">
</head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/shier_jinghuang/" class="waves-effect waves-light">
                    
                    <img src="/shier_jinghuang/medias/1.jpg" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">十二惊惶的gitee</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shier_jinghuang/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shier_jinghuang/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shier_jinghuang/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shier_jinghuang/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shier_jinghuang/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shier_jinghuang/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shier_jinghuang/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
  <li>
    <a href="javascript:;" class="waves-effect waves-light" onclick="switchNightMode()" title="深色/浅色模式" >
      <i id="sum-moon-icon" class="fas fa-sun" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/shier_jinghuang/medias/1.jpg" class="logo-img circle responsive-img">
        
        <div class="logo-name">十二惊惶的gitee</div>
        <div class="logo-desc">
            
            犁牛之子骍且角，虽欲勿用，山川其舍诸
            
        </div>
    </div>

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/shier_jinghuang/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shier_jinghuang/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shier_jinghuang/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shier_jinghuang/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shier_jinghuang/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shier_jinghuang/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shier_jinghuang/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://gitee.com/Im-so-scared-2/shier_jinghuang" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>十二惊惶
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://gitee.com/Im-so-scared-2/shier_jinghuang" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="十二惊惶" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/shier_jinghuang/medias/featureimages/8.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">计算机网络实训之简单文件传输系统器</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/shier_jinghuang/tags/%E5%AE%9E%E8%AE%AD%E8%AE%B0%E5%BD%95/">
                                <span class="chip bg-color">实训记录</span>
                            </a>
                        
                            <a href="/shier_jinghuang/tags/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/">
                                <span class="chip bg-color">计算机网络</span>
                            </a>
                        
                            <a href="/shier_jinghuang/tags/FTP/">
                                <span class="chip bg-color">FTP</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/shier_jinghuang/categories/%E7%BD%91%E7%BB%9C%E5%B7%A5%E7%A8%8B%E7%9B%B8%E5%85%B3/" class="post-category">
                                网络工程相关
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2022-09-08
                </div>
                

                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-check fa-fw"></i>更新日期:&nbsp;&nbsp;
                    2022-11-13
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    2.6k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    11 分
                </div>
                

                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
        </div>
        <hr class="clearfix">

        
        <!-- 是否加载使用自带的 prismjs. -->
        <link rel="stylesheet" href="/shier_jinghuang/libs/prism/prism.min.css">
        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <p>只能说计算机网络实训那一周我是真的难受，不仅仅有我自己的实训任务还有别人的，自己这个任务一实际上是第一天就写完了的，大部分的时间是在做网络的一些内容，以及同组其他成员的可视化。</p>
<hr>
<p>[TOC]</p>
<h2 id="简单文件传输系统器"><a href="#简单文件传输系统器" class="headerlink" title="简单文件传输系统器"></a>简单文件传输系统器</h2><h3 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h3><p>本文件传输系统为一款实现内网文件传输的类FTP协议软件，由Python语言开发。客户端程序与服务器端程序分别运行局域网内不同主机上，实现客户端与服务器端的文件传输功能。</p>
<h3 id="服务器界面："><a href="#服务器界面：" class="headerlink" title="服务器界面："></a>服务器界面：</h3><center><img src="https://im-so-scared-2.gitee.io/shier_jinghuang/2022/09/08/计算机网络实训/wps1.jpg"style="zoom:80%;" /><center> 



<center>图1-1 文件传输系统服务端</center>
该界面包括开始等待下载按钮和选择共享文件夹按钮。

<p>本程序是一款通过服务器客户端的方式实现一个类FTP协议下载功能的应用软件。</p>
<center><img src="https://im-so-scared-2.gitee.io/shier_jinghuang/2022/09/08/计算机网络实训/wps2.jpg" style="zoom:80%;" /> </center>
<center>图1-2 共享文件夹选择页面</center>

<p>点击选择共享文件夹按钮后，路径选择界面，选择文件夹作为共享文件夹，客户端可以自由获取该文件夹下的文件。同时服务器端会读取当前共享文件夹路径下的所有文件名，写入文件菜单.txt中。</p>
<p>在选择好共享文件后，点击开始等待下载，程序通过点击，服务器进入被动等待，同时服务器会进行弹窗展示自己的IP地址（内网地址）</p>
<center><img src="https://im-so-scared-2.gitee.io/shier_jinghuang/2022/09/08/计算机网络实训/wps3.jpg" style="zoom:80%;" /> </center>
<center>图1-3 弹窗显示服务器内网IP地址</center>

<p>在此之后，服务器端将等待客户端与其建立连接，连接建立后将持续等待客户端发送文件下载请求，但同一时间只能与一个客户端建立连接。</p>
<h3 id="客户端界面"><a href="#客户端界面" class="headerlink" title="客户端界面"></a>客户端界面</h3><p>首先运行客户端后，会进入客户端页面，如图2-1所示。 </p>
<center><img src="https://im-so-scared-2.gitee.io/shier_jinghuang/2022/09/08/计算机网络实训/wps4.jpg" style="zoom:80%;" /> </center>
<center>图2-1 客户端页面</center>

<p>该界面包括对应的服务器IP地址输入栏，文件输入栏。还有下载按钮和文件存放地址设置按钮。在服务器开启后依次输入输入服务器IP地址，与需要下载的文件，设置文件存放地址，点击下载程序将自动链接服务器，下载需下载的文件。</p>
<p>执行程序时，应先下载文件菜单.txt文件，以获悉共享文件夹下的内容。</p>
<p>当文件完成下载时会进行弹窗提示，用户可继续通过当前客户端下载服务器共享文件夹下的其他文件。</p>
<center><img src="https://im-so-scared-2.gitee.io/shier_jinghuang/2022/09/08/计算机网络实训/wps5.jpg" style="zoom:80%;" /> </center>
<center>图2-2文件下载完成后的相应提示</center>

<h3 id="开发环境"><a href="#开发环境" class="headerlink" title="开发环境"></a>开发环境</h3><p>本项目使用Python语言开发，使用 PyCharm编译器进行开发。使用WxPython库进行可视化界面制作，同时以socket,Json，struct等支持库进行服务器与客户端的链接。</p>
<p>在开发过程中，客户端程序与服务器端程序分开进行开发。</p>
<h3 id="使用注意事项"><a href="#使用注意事项" class="headerlink" title="使用注意事项"></a>使用注意事项</h3><ol>
<li><p>在使用时请在服务器地址下放置需要客户端下载的内容</p>
</li>
<li><p>由于使用支持库socket的限制，本程序只能实现在同一子网下不同主机间的通信，无法实现对内网的穿透实现外网通信。</p>
</li>
<li><p>由于windows计算机防火墙的存在，在设计传输程序的过程中，一直选用8000端口作为通信端口，同时手动开启服务器该端口号，只有服务器固定端口号打开时程序才能顺利运行。</p>
</li>
<li><p>客户端输入IP地址应为局域网内的内网地址，即程序运行过程中服务器端提示地址（原因见注意事项1）。</p>
</li>
<li><p>在实际应用时，进行了一些简单的过滤，避免客户端通过简单注入即可危害服务器信息安全（读取到不应读取的内容）。</p>
</li>
</ol>
<h3 id="服务器代码："><a href="#服务器代码：" class="headerlink" title="服务器代码："></a>服务器代码：</h3><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token comment"># -*- coding:utf-8 -*-</span>
<span class="token keyword">import</span> struct  <span class="token comment"># 制作报头的模块</span>
<span class="token keyword">import</span> json   <span class="token comment"># 转换数据格式(序列化)</span>
<span class="token keyword">import</span> wx<span class="token punctuation">.</span>lib<span class="token punctuation">.</span>agw<span class="token punctuation">.</span>hyperlink <span class="token keyword">as</span> lib_hyperlink
<span class="token keyword">import</span> wx
<span class="token keyword">import</span> os
<span class="token keyword">import</span> socket


<span class="token keyword">def</span> <span class="token function">getIP</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    s <span class="token operator">=</span> socket<span class="token punctuation">.</span>socket<span class="token punctuation">(</span>socket<span class="token punctuation">.</span>AF_INET<span class="token punctuation">,</span> socket<span class="token punctuation">.</span>SOCK_DGRAM<span class="token punctuation">)</span>
    s<span class="token punctuation">.</span>connect<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">"8.8.8.8"</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    ip<span class="token operator">=</span>s<span class="token punctuation">.</span>getsockname<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>
    <span class="token keyword">return</span> ip


<span class="token keyword">class</span> <span class="token class-name">Frame</span><span class="token punctuation">(</span>wx<span class="token punctuation">.</span>Frame<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token keyword">def</span> <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        self<span class="token punctuation">.</span>ip<span class="token operator">=</span>getIP<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>ip<span class="token punctuation">)</span>
        wx<span class="token punctuation">.</span>Frame<span class="token punctuation">.</span>__init__<span class="token punctuation">(</span>self<span class="token punctuation">,</span> <span class="token boolean">None</span><span class="token punctuation">,</span> title<span class="token operator">=</span><span class="token string">'简单文件传输器（服务器）'</span><span class="token punctuation">,</span> size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">360</span><span class="token punctuation">,</span> <span class="token number">300</span><span class="token punctuation">)</span><span class="token punctuation">,</span>name<span class="token operator">=</span><span class="token string">'frame'</span><span class="token punctuation">,</span>style<span class="token operator">=</span><span class="token number">541072384</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>qdck <span class="token operator">=</span> wx<span class="token punctuation">.</span>Panel<span class="token punctuation">(</span>self<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>Centre<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an1 <span class="token operator">=</span> wx<span class="token punctuation">.</span>Button<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span>size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">46</span><span class="token punctuation">)</span><span class="token punctuation">,</span>pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">190</span><span class="token punctuation">,</span> <span class="token number">115</span><span class="token punctuation">)</span><span class="token punctuation">,</span>label<span class="token operator">=</span><span class="token string">'开始等待下载'</span><span class="token punctuation">,</span>name<span class="token operator">=</span><span class="token string">'button'</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an1<span class="token punctuation">.</span>SetAuthNeeded<span class="token punctuation">(</span><span class="token boolean">True</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an1<span class="token punctuation">.</span>Bind<span class="token punctuation">(</span>wx<span class="token punctuation">.</span>EVT_BUTTON<span class="token punctuation">,</span>self<span class="token punctuation">.</span>an1_anbdj<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>bq1 <span class="token operator">=</span> wx<span class="token punctuation">.</span>StaticText<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span> size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">150</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span> pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span> label<span class="token operator">=</span><span class="token string">'简单文件传输器'</span><span class="token punctuation">,</span> name<span class="token operator">=</span><span class="token string">'staticText'</span><span class="token punctuation">,</span>
                                 style<span class="token operator">=</span><span class="token number">2321</span><span class="token punctuation">)</span>
        bq1_字体 <span class="token operator">=</span> wx<span class="token punctuation">.</span>Font<span class="token punctuation">(</span><span class="token number">16</span><span class="token punctuation">,</span> <span class="token number">74</span><span class="token punctuation">,</span> <span class="token number">90</span><span class="token punctuation">,</span> <span class="token number">700</span><span class="token punctuation">,</span> <span class="token boolean">False</span><span class="token punctuation">,</span> <span class="token string">'Microsoft YaHei UI'</span><span class="token punctuation">,</span> <span class="token number">28</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>bq1<span class="token punctuation">.</span>SetFont<span class="token punctuation">(</span>bq1_字体<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>port<span class="token operator">=</span><span class="token number">8000</span>
        <span class="token comment"># 设置默认端口号为8848 钛合金手机</span>
        self<span class="token punctuation">.</span>cjljkL1 <span class="token operator">=</span> lib_hyperlink<span class="token punctuation">.</span>HyperLinkCtrl<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span>size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">28</span><span class="token punctuation">)</span><span class="token punctuation">,</span>pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">150</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">,</span>name<span class="token operator">=</span><span class="token string">'staticText'</span><span class="token punctuation">,</span>
                                                   label<span class="token operator">=</span><span class="token string">'使用说明'</span><span class="token punctuation">,</span>URL<span class="token operator">=</span><span class="token string">'https://im-so-scared-2.gitee.io/shier_jinghuang/'</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>cjljkL1<span class="token punctuation">.</span>SetToolTip<span class="token punctuation">(</span>wx<span class="token punctuation">.</span>ToolTip<span class="token punctuation">(</span><span class="token string">'使用说明'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        cjljkL1_字体 <span class="token operator">=</span> wx<span class="token punctuation">.</span>Font<span class="token punctuation">(</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">70</span><span class="token punctuation">,</span><span class="token number">90</span><span class="token punctuation">,</span><span class="token number">400</span><span class="token punctuation">,</span><span class="token boolean">True</span><span class="token punctuation">,</span><span class="token string">'Microsoft YaHei UI'</span><span class="token punctuation">,</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>cjljkL1<span class="token punctuation">.</span>SetFont<span class="token punctuation">(</span>cjljkL1_字体<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>cjljkL1<span class="token punctuation">.</span>SetForegroundColour<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an2 <span class="token operator">=</span> wx<span class="token punctuation">.</span>Button<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span> size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">46</span><span class="token punctuation">)</span><span class="token punctuation">,</span> pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span><span class="token number">115</span><span class="token punctuation">)</span><span class="token punctuation">,</span> label<span class="token operator">=</span><span class="token string">'选择共享文件夹'</span><span class="token punctuation">,</span> name<span class="token operator">=</span><span class="token string">'button'</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an2<span class="token punctuation">.</span>Bind<span class="token punctuation">(</span>wx<span class="token punctuation">.</span>EVT_BUTTON<span class="token punctuation">,</span> self<span class="token punctuation">.</span>an2_anbdj<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an2<span class="token punctuation">.</span>SetAuthNeeded<span class="token punctuation">(</span><span class="token boolean">True</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>share_dir<span class="token operator">=</span><span class="token string">""</span>

    <span class="token keyword">def</span> <span class="token function">an1_anbdj</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span>event<span class="token punctuation">)</span><span class="token punctuation">:</span>
        toastone <span class="token operator">=</span> wx<span class="token punctuation">.</span>MessageDialog<span class="token punctuation">(</span><span class="token boolean">None</span><span class="token punctuation">,</span> <span class="token string">"服务器的IP地址为："</span><span class="token operator">+</span>self<span class="token punctuation">.</span>ip<span class="token operator">+</span><span class="token string">"!"</span><span class="token punctuation">,</span> <span class="token string">"IP地址显示"</span><span class="token punctuation">,</span> wx<span class="token punctuation">.</span>YES_DEFAULT <span class="token operator">|</span> wx<span class="token punctuation">.</span>ICON_QUESTION<span class="token punctuation">)</span>
        <span class="token keyword">if</span> toastone<span class="token punctuation">.</span>ShowModal<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> wx<span class="token punctuation">.</span>ID_YES<span class="token punctuation">:</span>
            <span class="token comment"># 如果点击了提示框的确定按钮</span>
            toastone<span class="token punctuation">.</span>Destroy<span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token comment"># 则关闭提示框</span>
        phone <span class="token operator">=</span> socket<span class="token punctuation">.</span>socket<span class="token punctuation">(</span>socket<span class="token punctuation">.</span>AF_INET<span class="token punctuation">,</span> socket<span class="token punctuation">.</span>SOCK_STREAM<span class="token punctuation">)</span>
        phone<span class="token punctuation">.</span>bind<span class="token punctuation">(</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>ip<span class="token punctuation">,</span> self<span class="token punctuation">.</span>port<span class="token punctuation">)</span><span class="token punctuation">)</span>
        phone<span class="token punctuation">.</span>listen<span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span>
        <span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
            conn<span class="token punctuation">,</span> client <span class="token operator">=</span> phone<span class="token punctuation">.</span>accept<span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
                    <span class="token comment"># 收命令</span>
                    res <span class="token operator">=</span> conn<span class="token punctuation">.</span>recv<span class="token punctuation">(</span><span class="token number">8096</span><span class="token punctuation">)</span>
                    <span class="token comment"># 解析命令、提取相应的命令参数</span>
                    cmds <span class="token operator">=</span> res<span class="token punctuation">.</span>decode<span class="token punctuation">(</span><span class="token string">'gbk'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment"># ['get','a.txt']  split变列表格式</span>
                    filename <span class="token operator">=</span> cmds<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span>
                    <span class="token comment"># 已读的方式打开文件，读取文件内容发送给客户端</span>
                    <span class="token comment"># 第一步：制作固定长度的报头</span>
                    header_dic <span class="token operator">=</span> <span class="token punctuation">&#123;</span>
                        <span class="token string">'filename'</span><span class="token punctuation">:</span> filename<span class="token punctuation">,</span>
                        <span class="token string">'file_size'</span><span class="token punctuation">:</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>getsize<span class="token punctuation">(</span><span class="token string">r'%s/%s'</span> <span class="token operator">%</span> <span class="token punctuation">(</span>self<span class="token punctuation">.</span>share_dir<span class="token punctuation">,</span> filename<span class="token punctuation">)</span><span class="token punctuation">)</span>
                        <span class="token comment"># 这里把文件的名字和地址结合在一起得到文件长度</span>
                    <span class="token punctuation">&#125;</span>  <span class="token comment"># 字典方便储存数据</span>
                    header_json <span class="token operator">=</span> json<span class="token punctuation">.</span>dumps<span class="token punctuation">(</span>header_dic<span class="token punctuation">)</span>  <span class="token comment"># 把字典转换成js格式(字符串类型)</span>
                    header_bytes <span class="token operator">=</span> header_json<span class="token punctuation">.</span>encode<span class="token punctuation">(</span><span class="token string">'gbk'</span><span class="token punctuation">)</span>
                    <span class="token comment"># 第二步：先发送报头的长度</span>
                    conn<span class="token punctuation">.</span>send<span class="token punctuation">(</span>struct<span class="token punctuation">.</span>pack<span class="token punctuation">(</span><span class="token string">'i'</span><span class="token punctuation">,</span> <span class="token builtin">len</span><span class="token punctuation">(</span>header_bytes<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
                    <span class="token comment"># 第三步：再发报头</span>
                    conn<span class="token punctuation">.</span>send<span class="token punctuation">(</span>header_bytes<span class="token punctuation">)</span>
                    <span class="token comment"># 第四步：发送真实数据</span>
                    <span class="token keyword">with</span> <span class="token builtin">open</span><span class="token punctuation">(</span><span class="token string">'%s/%s'</span> <span class="token operator">%</span> <span class="token punctuation">(</span>self<span class="token punctuation">.</span>share_dir<span class="token punctuation">,</span> filename<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">'rb'</span><span class="token punctuation">)</span> <span class="token keyword">as</span> f<span class="token punctuation">:</span>
                        <span class="token keyword">for</span> line <span class="token keyword">in</span> f<span class="token punctuation">:</span>
                            <span class="token comment"># 这样一行一行发比直接发送f.read节省内存空间</span>
                            conn<span class="token punctuation">.</span>send<span class="token punctuation">(</span>line<span class="token punctuation">)</span>
                    conn<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
                    <span class="token comment"># except ConnectionResetError as err:</span>
                    <span class="token comment"># break</span>
                    <span class="token keyword">break</span>
        phone<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>

    <span class="token keyword">def</span> <span class="token function">bjk1_axEnterj</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span>event<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token comment"># print('bjk1,按下Enter键')</span>
        <span class="token comment"># print(self.share_dir)</span>
        <span class="token keyword">pass</span>

    <span class="token keyword">def</span> <span class="token function">an2_anbdj</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span>event<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token comment"># print('an2,按钮被单击')</span>
        dialog <span class="token operator">=</span> wx<span class="token punctuation">.</span>DirDialog<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span> message<span class="token operator">=</span><span class="token string">"打开文件夹"</span><span class="token punctuation">,</span> style<span class="token operator">=</span>wx<span class="token punctuation">.</span>DD_CHANGE_DIR<span class="token punctuation">)</span>
        <span class="token keyword">if</span> dialog<span class="token punctuation">.</span>ShowModal<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> wx<span class="token punctuation">.</span>ID_OK<span class="token punctuation">:</span>
            filename <span class="token operator">=</span> dialog<span class="token punctuation">.</span>GetPath<span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span>filename<span class="token punctuation">)</span>
            self<span class="token punctuation">.</span>share_dir<span class="token operator">=</span><span class="token builtin">str</span><span class="token punctuation">(</span>filename<span class="token punctuation">)</span>
            img_list <span class="token operator">=</span> os<span class="token punctuation">.</span>listdir<span class="token punctuation">(</span>self<span class="token punctuation">.</span>share_dir<span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span>img_list<span class="token punctuation">)</span>
            <span class="token builtin">file</span> <span class="token operator">=</span> <span class="token builtin">open</span><span class="token punctuation">(</span><span class="token string">'文件菜单.txt'</span><span class="token punctuation">,</span> <span class="token string">'w'</span><span class="token punctuation">)</span>  <span class="token comment"># 创建文件，权限为写入</span>
            <span class="token keyword">for</span> img_name <span class="token keyword">in</span> img_list<span class="token punctuation">:</span>
                <span class="token builtin">file</span><span class="token punctuation">.</span>write<span class="token punctuation">(</span>img_name <span class="token operator">+</span> <span class="token string">'\n'</span><span class="token punctuation">)</span>
            toastone <span class="token operator">=</span> wx<span class="token punctuation">.</span>MessageDialog<span class="token punctuation">(</span><span class="token boolean">None</span><span class="token punctuation">,</span> <span class="token string">"文件菜单已创建"</span><span class="token punctuation">,</span> <span class="token string">"软件提示"</span><span class="token punctuation">,</span> wx<span class="token punctuation">.</span>YES_DEFAULT <span class="token operator">|</span> wx<span class="token punctuation">.</span>ICON_QUESTION<span class="token punctuation">)</span>
            <span class="token keyword">if</span> toastone<span class="token punctuation">.</span>ShowModal<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> wx<span class="token punctuation">.</span>ID_YES<span class="token punctuation">:</span>
                <span class="token comment"># 如果点击了提示框的确定按钮</span>
                toastone<span class="token punctuation">.</span>Destroy<span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token comment"># 则关闭提示框</span>
            dialog<span class="token punctuation">.</span>Destroy<span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token keyword">class</span> <span class="token class-name">myApp</span><span class="token punctuation">(</span>wx<span class="token punctuation">.</span>App<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token keyword">def</span> <span class="token function">OnInit</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        self<span class="token punctuation">.</span>frame <span class="token operator">=</span> Frame<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>frame<span class="token punctuation">.</span>Show<span class="token punctuation">(</span><span class="token boolean">True</span><span class="token punctuation">)</span>
        <span class="token keyword">return</span> <span class="token boolean">True</span>

<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    app <span class="token operator">=</span> myApp<span class="token punctuation">(</span><span class="token punctuation">)</span>
    app<span class="token punctuation">.</span>MainLoop<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="客户端："><a href="#客户端：" class="headerlink" title="客户端："></a>客户端：</h3><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token comment"># -*- coding:utf-8 -*-</span>
<span class="token keyword">import</span> wx<span class="token punctuation">.</span>lib<span class="token punctuation">.</span>agw<span class="token punctuation">.</span>hyperlink <span class="token keyword">as</span> lib_hyperlink
<span class="token keyword">import</span> wx
<span class="token keyword">import</span> socket
<span class="token keyword">import</span> struct  <span class="token comment"># 制作报头的模块</span>
<span class="token keyword">import</span> json   <span class="token comment"># 转换数据格式(序列化)</span>


<span class="token keyword">class</span> <span class="token class-name">Frame</span><span class="token punctuation">(</span>wx<span class="token punctuation">.</span>Frame<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token keyword">def</span> <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        wx<span class="token punctuation">.</span>Frame<span class="token punctuation">.</span>__init__<span class="token punctuation">(</span>self<span class="token punctuation">,</span> <span class="token boolean">None</span><span class="token punctuation">,</span> title<span class="token operator">=</span><span class="token string">'简单文件传输器（客户端）'</span><span class="token punctuation">,</span> size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">800</span><span class="token punctuation">,</span> <span class="token number">300</span><span class="token punctuation">)</span><span class="token punctuation">,</span>name<span class="token operator">=</span><span class="token string">'frame'</span><span class="token punctuation">,</span>style<span class="token operator">=</span><span class="token number">541072384</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>qdck <span class="token operator">=</span> wx<span class="token punctuation">.</span>Panel<span class="token punctuation">(</span>self<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>Centre<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an1 <span class="token operator">=</span> wx<span class="token punctuation">.</span>Button<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span>size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">46</span><span class="token punctuation">)</span><span class="token punctuation">,</span>pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">135</span><span class="token punctuation">)</span><span class="token punctuation">,</span>label<span class="token operator">=</span><span class="token string">'下载'</span><span class="token punctuation">,</span>name<span class="token operator">=</span><span class="token string">'button'</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an1<span class="token punctuation">.</span>SetAuthNeeded<span class="token punctuation">(</span><span class="token boolean">True</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an1<span class="token punctuation">.</span>Bind<span class="token punctuation">(</span>wx<span class="token punctuation">.</span>EVT_BUTTON<span class="token punctuation">,</span>self<span class="token punctuation">.</span>an1_anbdj<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>bjk1 <span class="token operator">=</span> wx<span class="token punctuation">.</span>TextCtrl<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span>size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">400</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span>pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">300</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span>value<span class="token operator">=</span><span class="token string">''</span><span class="token punctuation">,</span>name<span class="token operator">=</span><span class="token string">'text'</span><span class="token punctuation">,</span>style<span class="token operator">=</span><span class="token number">4096</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>bjk1<span class="token punctuation">.</span>SetMaxLength<span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>bq1 <span class="token operator">=</span> wx<span class="token punctuation">.</span>StaticText<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span>size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">265</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span>pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span>label<span class="token operator">=</span><span class="token string">'请输入服务器IP地址:'</span><span class="token punctuation">,</span>name<span class="token operator">=</span><span class="token string">'staticText'</span><span class="token punctuation">,</span>style<span class="token operator">=</span><span class="token number">2321</span><span class="token punctuation">)</span>
        bq1_字体 <span class="token operator">=</span> wx<span class="token punctuation">.</span>Font<span class="token punctuation">(</span><span class="token number">16</span><span class="token punctuation">,</span><span class="token number">74</span><span class="token punctuation">,</span><span class="token number">90</span><span class="token punctuation">,</span><span class="token number">700</span><span class="token punctuation">,</span><span class="token boolean">False</span><span class="token punctuation">,</span><span class="token string">'Microsoft YaHei UI'</span><span class="token punctuation">,</span><span class="token number">28</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>bq1<span class="token punctuation">.</span>SetFont<span class="token punctuation">(</span>bq1_字体<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>bq2 <span class="token operator">=</span> wx<span class="token punctuation">.</span>StaticText<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span> size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">265</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span> pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">70</span><span class="token punctuation">)</span><span class="token punctuation">,</span> label<span class="token operator">=</span><span class="token string">'请输入需要下载的文件:'</span><span class="token punctuation">,</span> name<span class="token operator">=</span><span class="token string">'staticText'</span><span class="token punctuation">,</span>
                                 style<span class="token operator">=</span><span class="token number">2321</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>bq2<span class="token punctuation">.</span>SetFont<span class="token punctuation">(</span>bq1_字体<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>bjk2 <span class="token operator">=</span> wx<span class="token punctuation">.</span>TextCtrl<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span> size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">400</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span> pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">300</span><span class="token punctuation">,</span> <span class="token number">70</span><span class="token punctuation">)</span><span class="token punctuation">,</span> value<span class="token operator">=</span><span class="token string">''</span><span class="token punctuation">,</span> name<span class="token operator">=</span><span class="token string">'text'</span><span class="token punctuation">,</span> style<span class="token operator">=</span><span class="token number">4096</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>bjk2<span class="token punctuation">.</span>SetMaxLength<span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>cjljkL1 <span class="token operator">=</span> lib_hyperlink<span class="token punctuation">.</span>HyperLinkCtrl<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span>size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">28</span><span class="token punctuation">)</span><span class="token punctuation">,</span>pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">380</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">,</span>name<span class="token operator">=</span><span class="token string">'staticText'</span><span class="token punctuation">,</span>
                                                   label<span class="token operator">=</span><span class="token string">'使用说明'</span><span class="token punctuation">,</span>URL<span class="token operator">=</span><span class="token string">'https://im-so-scared-2.gitee.io/shier_jinghuang/'</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>cjljkL1<span class="token punctuation">.</span>SetToolTip<span class="token punctuation">(</span>wx<span class="token punctuation">.</span>ToolTip<span class="token punctuation">(</span><span class="token string">'使用说明'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        cjljkL1_字体 <span class="token operator">=</span> wx<span class="token punctuation">.</span>Font<span class="token punctuation">(</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">70</span><span class="token punctuation">,</span><span class="token number">90</span><span class="token punctuation">,</span><span class="token number">400</span><span class="token punctuation">,</span><span class="token boolean">True</span><span class="token punctuation">,</span><span class="token string">'Microsoft YaHei UI'</span><span class="token punctuation">,</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>cjljkL1<span class="token punctuation">.</span>SetFont<span class="token punctuation">(</span>cjljkL1_字体<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>cjljkL1<span class="token punctuation">.</span>SetForegroundColour<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an2 <span class="token operator">=</span> wx<span class="token punctuation">.</span>Button<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span> size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">46</span><span class="token punctuation">)</span><span class="token punctuation">,</span> pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">450</span><span class="token punctuation">,</span> <span class="token number">135</span><span class="token punctuation">)</span><span class="token punctuation">,</span> label<span class="token operator">=</span><span class="token string">'选择文件存放地址'</span><span class="token punctuation">,</span> name<span class="token operator">=</span><span class="token string">'button'</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an2<span class="token punctuation">.</span>Bind<span class="token punctuation">(</span>wx<span class="token punctuation">.</span>EVT_BUTTON<span class="token punctuation">,</span> self<span class="token punctuation">.</span>an2_anbdj<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an2<span class="token punctuation">.</span>SetAuthNeeded<span class="token punctuation">(</span><span class="token boolean">True</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>share_dir <span class="token operator">=</span> <span class="token string">""</span>

    <span class="token keyword">def</span> <span class="token function">an2_anbdj</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span>event<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token comment"># print('an2,按钮被单击')</span>
        dialog <span class="token operator">=</span> wx<span class="token punctuation">.</span>DirDialog<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span> message<span class="token operator">=</span><span class="token string">"请选择文件存放地址"</span><span class="token punctuation">,</span> style<span class="token operator">=</span>wx<span class="token punctuation">.</span>DD_CHANGE_DIR<span class="token punctuation">)</span>
        <span class="token keyword">if</span> dialog<span class="token punctuation">.</span>ShowModal<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> wx<span class="token punctuation">.</span>ID_OK<span class="token punctuation">:</span>
            filename <span class="token operator">=</span> dialog<span class="token punctuation">.</span>GetPath<span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span>filename<span class="token punctuation">)</span>
            self<span class="token punctuation">.</span>share_dir <span class="token operator">=</span> <span class="token builtin">str</span><span class="token punctuation">(</span>filename<span class="token punctuation">)</span>
            dialog<span class="token punctuation">.</span>Destroy<span class="token punctuation">(</span><span class="token punctuation">)</span>

    <span class="token keyword">def</span> <span class="token function">an1_anbdj</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span>event<span class="token punctuation">)</span><span class="token punctuation">:</span>
        self<span class="token punctuation">.</span>ip<span class="token operator">=</span>self<span class="token punctuation">.</span>bjk1<span class="token punctuation">.</span>GetValue<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>filename<span class="token operator">=</span>self<span class="token punctuation">.</span>bjk2<span class="token punctuation">.</span>GetValue<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>filename<span class="token punctuation">)</span>
        phone <span class="token operator">=</span> socket<span class="token punctuation">.</span>socket<span class="token punctuation">(</span>socket<span class="token punctuation">.</span>AF_INET<span class="token punctuation">,</span> socket<span class="token punctuation">.</span>SOCK_STREAM<span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>ip<span class="token punctuation">)</span>
        cmd <span class="token operator">=</span> <span class="token string">"get "</span> <span class="token operator">+</span> self<span class="token punctuation">.</span>filename
        <span class="token keyword">print</span><span class="token punctuation">(</span>cmd<span class="token punctuation">)</span>
        phone<span class="token punctuation">.</span>connect<span class="token punctuation">(</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>ip<span class="token punctuation">,</span> <span class="token number">8000</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"------开始咨询客服---------"</span><span class="token punctuation">)</span>
        <span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
            <span class="token comment"># 发命令</span>
            <span class="token comment"># get a.txt</span>
            <span class="token keyword">if</span> cmd<span class="token operator">==</span><span class="token string">'a'</span><span class="token punctuation">:</span>
                <span class="token keyword">break</span>
            phone<span class="token punctuation">.</span>send<span class="token punctuation">(</span>cmd<span class="token punctuation">.</span>encode<span class="token punctuation">(</span><span class="token string">"gbk"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token comment"># 已写的方式打开一个新文件，接收服务器发来的文件的内容写入客户端的新文件</span>
            <span class="token comment"># 第一步：先收取报头的长度</span>
            obj <span class="token operator">=</span> phone<span class="token punctuation">.</span>recv<span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span>
            header_size <span class="token operator">=</span> struct<span class="token punctuation">.</span>unpack<span class="token punctuation">(</span><span class="token string">'i'</span><span class="token punctuation">,</span> obj<span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>
            <span class="token comment"># 第二步：再收报头</span>
            header_bytes <span class="token operator">=</span> phone<span class="token punctuation">.</span>recv<span class="token punctuation">(</span>header_size<span class="token punctuation">)</span>
            <span class="token comment"># 第三步：从报头中间解析出对真是数据的描述信息</span>
            header_json <span class="token operator">=</span> header_bytes<span class="token punctuation">.</span>decode<span class="token punctuation">(</span><span class="token string">'gbk'</span><span class="token punctuation">)</span>
            header_dic <span class="token operator">=</span> json<span class="token punctuation">.</span>loads<span class="token punctuation">(</span>header_json<span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span>header_dic<span class="token punctuation">)</span>
            total_size <span class="token operator">=</span> header_dic<span class="token punctuation">[</span><span class="token string">'file_size'</span><span class="token punctuation">]</span>
            filename <span class="token operator">=</span> header_dic<span class="token punctuation">[</span><span class="token string">'filename'</span><span class="token punctuation">]</span>
            <span class="token comment"># 第三步：接受真实的数据</span>
            <span class="token keyword">with</span> <span class="token builtin">open</span><span class="token punctuation">(</span><span class="token string">'%s/%s'</span> <span class="token operator">%</span> <span class="token punctuation">(</span>self<span class="token punctuation">.</span>share_dir<span class="token punctuation">,</span> filename<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">'wb'</span><span class="token punctuation">)</span> <span class="token keyword">as</span> f<span class="token punctuation">:</span>  <span class="token comment"># 在自己的电脑中找一个地址打开一个同类型的文件准备接收数据</span>
                recv_size <span class="token operator">=</span> <span class="token number">0</span>
                <span class="token keyword">while</span> recv_size <span class="token operator">&lt;</span> total_size<span class="token punctuation">:</span>
                    line <span class="token operator">=</span> phone<span class="token punctuation">.</span>recv<span class="token punctuation">(</span><span class="token number">1024</span><span class="token punctuation">)</span>
                    f<span class="token punctuation">.</span>write<span class="token punctuation">(</span>line<span class="token punctuation">)</span>
                    recv_size <span class="token operator">+=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>line<span class="token punctuation">)</span>
                    <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'总大小：%s   已下载大小：%s'</span> <span class="token operator">%</span> <span class="token punctuation">(</span>total_size<span class="token punctuation">,</span> recv_size<span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment"># 显示下载进度</span>
            cmd<span class="token operator">=</span><span class="token string">'a'</span>
            toastone <span class="token operator">=</span> wx<span class="token punctuation">.</span>MessageDialog<span class="token punctuation">(</span><span class="token boolean">None</span><span class="token punctuation">,</span> <span class="token string">"文件下载完成!"</span><span class="token punctuation">,</span> <span class="token string">"信息提示"</span><span class="token punctuation">,</span> wx<span class="token punctuation">.</span>YES_DEFAULT <span class="token operator">|</span> wx<span class="token punctuation">.</span>ICON_QUESTION<span class="token punctuation">)</span>
            <span class="token keyword">if</span> toastone<span class="token punctuation">.</span>ShowModal<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> wx<span class="token punctuation">.</span>ID_YES<span class="token punctuation">:</span>
                <span class="token comment"># 如果点击了提示框的确定按钮</span>
                toastone<span class="token punctuation">.</span>Destroy<span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token comment"># 则关闭提示框</span>
        phone<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>


<span class="token keyword">class</span> <span class="token class-name">myApp</span><span class="token punctuation">(</span>wx<span class="token punctuation">.</span>App<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token keyword">def</span> <span class="token function">OnInit</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        self<span class="token punctuation">.</span>frame <span class="token operator">=</span> Frame<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>frame<span class="token punctuation">.</span>Show<span class="token punctuation">(</span><span class="token boolean">True</span><span class="token punctuation">)</span>
        <span class="token keyword">return</span> <span class="token boolean">True</span>


<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    app <span class="token operator">=</span> myApp<span class="token punctuation">(</span><span class="token punctuation">)</span>
    app<span class="token punctuation">.</span>MainLoop<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="写在最后："><a href="#写在最后：" class="headerlink" title="写在最后："></a>写在最后：</h3><p>这个简单文件传输器是真的简单，基本上还是点对点的下载，只是我想尝试模拟FTP协议，但是发现如果用py开启这个协议，实验完全就是协议的工作了，这个文件传输器就变成了协议开启器。</p>
<p>在权衡之后，我采用了在服务器端读取设置的共享文件夹的文件名，并将其写成一个文件，客户端通过下载该文件可以实现对其他文件的可知。</p>
<p>当我在第二天一开始，把这个代码写完时，我以为我接下来的任务会很轻松然后………..</p>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/shier_jinghuang/about" rel="external nofollow noreferrer">十二惊惶</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://im-so-scared-2.gitee.io/shier_jinghuang/shier_jinghuang/2022/09/08/%E7%AE%80%E5%8D%95%E6%96%87%E4%BB%B6%E4%BC%A0%E8%BE%93%E5%99%A8/">https://im-so-scared-2.gitee.io/shier_jinghuang/shier_jinghuang/2022/09/08/%E7%AE%80%E5%8D%95%E6%96%87%E4%BB%B6%E4%BC%A0%E8%BE%93%E5%99%A8/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/shier_jinghuang/about" target="_blank">十二惊惶</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/shier_jinghuang/tags/%E5%AE%9E%E8%AE%AD%E8%AE%B0%E5%BD%95/">
                                    <span class="chip bg-color">实训记录</span>
                                </a>
                            
                                <a href="/shier_jinghuang/tags/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/">
                                    <span class="chip bg-color">计算机网络</span>
                                </a>
                            
                                <a href="/shier_jinghuang/tags/FTP/">
                                    <span class="chip bg-color">FTP</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/shier_jinghuang/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/shier_jinghuang/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
        </div>
    </div>

    

    

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/shier_jinghuang/2022/09/23/Ubuntu_Docker%E5%AE%89%E8%A3%85/">
                    <div class="card-image">
                        
                        
                        <img src="/shier_jinghuang/medias/featureimages/14.jpg" class="responsive-img" alt="Ubuntu之docker安装：">
                        
                        <span class="card-title">Ubuntu之docker安装：</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2022-09-23
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/shier_jinghuang/categories/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" class="post-category">
                                    学习笔记
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/shier_jinghuang/tags/%E5%AD%A6%E4%B9%A0%E8%AE%B0%E5%BD%95/">
                        <span class="chip bg-color">学习记录</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/shier_jinghuang/2022/09/08/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%AE%9E%E8%AE%AD/">
                    <div class="card-image">
                        
                        
                        <img src="/shier_jinghuang/medias/featureimages/22.jpg" class="responsive-img" alt="计算机网络实训">
                        
                        <span class="card-title">计算机网络实训</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2022-09-08
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/shier_jinghuang/categories/%E7%BD%91%E7%BB%9C%E5%B7%A5%E7%A8%8B%E7%9B%B8%E5%85%B3/" class="post-category">
                                    网络工程相关
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/shier_jinghuang/tags/%E5%AE%9E%E8%AE%AD%E8%AE%B0%E5%BD%95/">
                        <span class="chip bg-color">实训记录</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/shier_jinghuang/libs/codeBlock/codeBlockFuction.js"></script>


  <!-- 是否加载使用自带的 prismjs. -->
  <script type="text/javascript" src="/shier_jinghuang/libs/prism/prism.min.js"></script>


<!-- 代码语言 -->

<script type="text/javascript" src="/shier_jinghuang/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/shier_jinghuang/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/shier_jinghuang/libs/codeBlock/codeShrink.js"></script>



    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/shier_jinghuang/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="/shier_jinghuang/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        
        display: none;
        
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        
        display: none;
        
        font-size: 15px;
        color: #42b983;
    }

    
    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
        left: -66px !important;
    }

    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
        left: 0px !important;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="503838841"
                   fixed='true'
                   autoplay='false'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/shier_jinghuang/libs/aplayer/APlayer.min.js"></script>
<script src="/shier_jinghuang/libs/aplayer/Meting.min.js"></script>

    

    <div class="container row center-align"
         style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2019-2023</span>
            
            <a href="/shier_jinghuang/about" target="_blank">十二惊惶</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
                &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                        class="white-color">289.6k</span>
            
            
            
                
            
            
                <span id="busuanzi_container_site_pv">
                &nbsp;|&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;
                    <span id="busuanzi_value_site_pv" class="white-color"></span>
            </span>
            
            
                <span id="busuanzi_container_site_uv">
                &nbsp;|&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;
                    <span id="busuanzi_value_site_uv" class="white-color"></span>
            </span>
            
            <br>

            <!-- 运行天数提醒. -->
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/blinkfox" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:1181062873@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=1181062873" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 1181062873" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/shier_jinghuang/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/shier_jinghuang/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 白天和黑夜主题 -->
<div class="stars-con">
    <div id="stars"></div>
    <div id="stars2"></div>
    <div id="stars3"></div>  
</div>

<script>
    function switchNightMode() {
        $('<div class="Cuteen_DarkSky"><div class="Cuteen_DarkPlanet"></div></div>').appendTo($('body')),
        setTimeout(function () {
            $('body').hasClass('DarkMode') 
            ? ($('body').removeClass('DarkMode'), localStorage.setItem('isDark', '0'), $('#sum-moon-icon').removeClass("fa-sun").addClass('fa-moon')) 
            : ($('body').addClass('DarkMode'), localStorage.setItem('isDark', '1'), $('#sum-moon-icon').addClass("fa-sun").removeClass('fa-moon')),
            
            setTimeout(function () {
            $('.Cuteen_DarkSky').fadeOut(1e3, function () {
                $(this).remove()
            })
            }, 2e3)
        })
    }
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/shier_jinghuang/libs/materialize/materialize.min.js"></script>
    <script src="/shier_jinghuang/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/shier_jinghuang/libs/aos/aos.js"></script>
    <script src="/shier_jinghuang/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/shier_jinghuang/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/shier_jinghuang/js/matery.js"></script>

    

    

    <!-- 雪花特效 -->
    

    <!-- 鼠标星星特效 -->
    

     
        <script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>
        <script src="/shier_jinghuang/libs/others/TencentCaptcha.js"></script>
        <button id="TencentCaptcha" data-appid="xxxxxxxxxx" data-cbfn="callback" type="button" hidden></button>
    

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/shier_jinghuang/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/shier_jinghuang/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    <!--腾讯兔小巢-->
    
    

    

    

    
    <script src="/shier_jinghuang/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
